home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / Snippets / QuickDraw / ClutWind / CLUTSampleMisc.a < prev   
Encoding:
Text File  |  1992-07-15  |  28.3 KB  |  749 lines  |  [TEXT/MPS ]

  1. *
  2. *    Apple Macintosh Developer Technical Support
  3. *
  4. *    CLUTSample
  5. *
  6. *    CLUTSampleMisc.a    -    Assembler Source
  7. *
  8. *
  9. *       Loosely based in the sample SAMPLE this program shows
  10. *       how to create a window and display on it the colors of the CLUT
  11. *    associated with the device the window sits on top of.
  12. *
  13. *    Left to the curious reader are some improvements such as, remembering the
  14. *    positions of each open window, so if you use this program to monitor your
  15. *    color tables it will position the windows in the last place you opened them.
  16. *    The treatment of direct devices is kind of 'casual' a better color display may 
  17. *    be appropriate. Last, it may be desireable to change the size of the color
  18. *    rectangles depending on the depth of the color table.
  19.  
  20. *    Check Sample sources for more detailed documentation.
  21.  
  22. *    Copyright © 1990 Apple Computer, Inc.
  23. *    All rights reserved.
  24.  
  25.  
  26. * ================================================
  27. * -------------- INCLUDES SECTION ----------------
  28. * ================================================
  29.  
  30.     PRINT    PUSH,OFF            ; don't print any of this stuff
  31.  
  32.     INCLUDE    'ToolEqu.a'
  33.     INCLUDE    'Traps.a'
  34.     INCLUDE    'PackMacs.a'
  35.     INCLUDE    'QuickEqu.a'
  36.     INCLUDE    'SysEqu.a'
  37.     INCLUDE    'CLUTSample.inc1.a'        ; all our macros and data templates
  38.  
  39.     PRINT    POP                ; restore the PRINT options
  40.  
  41.  
  42. * ================================================
  43. * -----------  DATA STORAGE USAGE  ---------------
  44. * ================================================
  45.         IMPORT    QD:QDGlobals
  46.         IMPORT    G:AppGlobals
  47.  
  48.  
  49. * ================================================
  50. * FUNCTION TrapAvailable(tNumber: INTEGER): BOOLEAN;
  51. * ================================================
  52.         SEG    'Initialize'        ; case sensitive
  53. TrapAvailable    FUNC    EXPORT            ; any source file can use this routine
  54.  
  55. StackFrame    RECORD    {A6Link},DECR        ; build a stack frame record
  56. Result        DS.W    1            ; function's result returned to caller
  57. ParamBegin    EQU    *            ; start parameters after this point
  58. tNumber        DS.W    1            ; the trap number passed by caller
  59. ParamSize    EQU    ParamBegin-*        ; size of all the passed parameters
  60. RetAddr     DS.L    1            ; place holder for return address
  61. A6Link        DS.L    1            ; place holder for A6 link
  62. TrapAddress    DS.L    1            ; local copy of trap address
  63. LocalSize    EQU     *            ; size of all the local variables
  64.         ENDR
  65.  
  66.         WITH    StackFrame        ; cover our local stack frame
  67.         LINK    A6,#LocalSize        ; allocate our local stack frame
  68.  
  69.         MOVE.W    #False,Result(A6)    ; initialize function's result
  70.  
  71.         MOVE.W    tNumber(A6),D0        ; get trap word into D0
  72.         BTST    #ToolTrapBit,D0        ; test if number is Tool trap
  73.         BEQ.S    GetOSTrap        ; off means a new OS trap number
  74.         
  75.         MOVE.W    G.Mac.machineType,D1    ; get the machine type we're running
  76.         CMPI.W    #envMachUnknown,D1    ; are we on a future machine?
  77.         BEQ.S    GetToolTrap        ; yes, go ahead and test for a new Tool trap
  78.         
  79.         CMPI.W    #envMacII,D1        ; are we on a Mac II or better?
  80.         BGE.S    GetToolTrap        ; yes, go ahead and test for a new Tool trap
  81.  
  82. * ------------- TEST FOR EXCEEDING TRAP TABLE -------------
  83. * At this point we know we're on a Mac 512E, Plus, or SE and need to
  84. * test the trap number for being in the range of < $0200
  85.  
  86.         AND.W    #$03FF,D0        ; mask off the ToolTrap bits
  87.         CMPI.W    #$01FF,D0        ; is this trap in our trap table?
  88.         BLE.S    GetToolTrap        ; yes, go ahead and test for a new Tool trap
  89.         BRA.S    Exit            ; no, then this trap cannot be present
  90.         
  91. * ------------- TEST FOR NEW TOOL TRAP -------------
  92.  
  93. GetToolTrap    _GetTrapAddress ,NewTool    ; NewTool trap macro, trap is in D0
  94.         MOVE.L    A0,TrapAddress(A6)    ; save a copy of the trap address
  95.         BRA.S    TestUnimp        ; test against Unimplemented trap
  96.         
  97. * ------------- TEST FOR NEW OS TRAP -------------
  98.  
  99. GetOSTrap    _GetTrapAddress ,NewOS        ; NewOS trap macro, trap is in D0
  100.         MOVE.L    A0,TrapAddress(A6)    ; save a copy of the trap address
  101. TestUnimp    MOVE.W    #Unimplemented,D0    ; get address of Unimplemented trap
  102.         _GetTrapAddress
  103.         CMPA.L    TrapAddress(A6),A0    ; see if trap is implemented
  104.         BEQ.S    Exit            ; nope, they're the same
  105.         MOVE.W    #True,Result(A6)    ; yes, we've got the trap
  106.  
  107. Exit        UNLK    A6            ; destroy the link
  108.         MOVEA.L    (SP)+,A0        ; pull off the return address
  109.         ADDA.L    #ParamSize,SP        ; strip all of the caller's parameters
  110.         JMP    (A0)            ; return to the caller
  111.  
  112.         DbgInfo    TrapAval        ; this name will appear in the debugger
  113.         ENDF
  114.  
  115. * ================================================
  116. * FUNCTION GoGetRect(rectID: INTEGER; VAR theRect: Rect) : BOOLEAN;
  117. * ================================================
  118. * This utility loads the global rectangles that are used by the window
  119. * drawing routines. It shows how the resource manager can be used to hold
  120. * values in a convenient manner. These values are then easily altered without
  121. * having to re-compile the source code. GoGetRect will return a BOOLEAN that
  122. * indicates if it was successful in getting the rectangle.
  123.  
  124. * A0 is being used for resource handle.
  125.  
  126.         SEG    'Initialize'        ; case sensitive
  127. GoGetRect    FUNC    EXPORT            ; any source file can use this routine
  128.  
  129. StackFrame    RECORD    {A6Link},DECR        ; build a stack frame record
  130. Result        DS.W    1            ; function's result returned to caller
  131. ParamBegin    EQU    *            ; start parameters after this point
  132. RectID        DS.W    1            ; resource ID of rect passed by caller
  133. TheRect        DS.L    1            ; the rect's pointer passed by caller
  134. ParamSize    EQU    ParamBegin-*        ; size of all the passed parameters
  135. RetAddr     DS.L    1            ; place holder for return address
  136. A6Link        DS.L    1            ; place holder for A6 link
  137. LocalSize    EQU     *            ; size of all the local variables
  138.         ENDR
  139.  
  140.         WITH    StackFrame        ; cover our local stack frame
  141.         LINK    A6,#LocalSize        ; allocate our local stack frame
  142.  
  143.         MOVE.W    #False,Result(A6)    ; initialize function's result
  144.  
  145.         CLR.L    -(SP)            ; create space for result
  146.         MOVE.L    #'RECT',-(SP)
  147.         MOVE.W    RectID(A6),-(SP)    ; get the stop light's rect
  148.         _GetResource
  149.         MOVEA.L    (SP)+,A0        ; handle to RECT resource in A0
  150.         CMPA.L    #NIL,A0            ; test for NIL handle
  151.         BEQ.S    Exit            ; didn't get resource, exit this procedure
  152.  
  153.  
  154. * -------- COPY THE RESOURCE TO THE RECT --------
  155.  
  156.         MOVE.W    #True,Result(A6)    ; we got the resource, return true
  157.         MOVEA.L    (A0),A0            ; pointer to RECT resource in A0
  158.         MOVEA.L    TheRect(A6),A1        ; pointer to the dest. RECT in A1
  159.         MOVE.L    topLeft(A0),topLeft(A1)    ; copy to the rect passed to us
  160.         MOVE.L    botRight(A0),botRight(A1)
  161.  
  162. Exit        UNLK    A6            ; destroy the link
  163.         MOVEA.L    (SP)+,A0        ; pull off the return address
  164.         ADDA.L    #ParamSize,SP        ; strip all of the caller's parameters
  165.         JMP    (A0)            ; return to the caller
  166.  
  167.         DbgInfo    GetRect            ; this name will appear in the debugger
  168.         ENDF
  169.  
  170. * ================================================
  171. * FUNCTION IsDAWindow(window: WindowPtr): BOOLEAN;
  172. * ================================================
  173. * Check if a window belongs to a desk accessory.  DA window has a negitive kind.
  174.  
  175.         SEG    'Main'
  176. IsDAWindow    FUNC    EXPORT            ; any source file can use this routine
  177.  
  178. StackFrame    RECORD    {A6Link},DECR        ; build a stack frame record
  179. Result        DS.W    1            ; function's result returned to caller
  180. ParamBegin    EQU    *            ; start parameters after this point
  181. TheWindow    DS.L    1            ; a window's pointer passed by caller
  182. ParamSize    EQU    ParamBegin-*        ; size of all the passed parameters
  183. RetAddr     DS.L    1            ; place holder for return address
  184. A6Link        DS.L    1            ; place holder for A6 link
  185. LocalSize    EQU     *            ; size of all the local variables
  186.         ENDR
  187.  
  188.         WITH    StackFrame        ; cover our local stack frame
  189.         LINK    A6,#LocalSize        ; allocate our local stack frame
  190.  
  191.         MOVE.W    #False,Result(A6)    ; first, initialize the result
  192.         CMPI.L    #NIL,TheWindow(A6)    ; valid pointer?
  193.         BEQ.S    Exit            ; it was NIL, look out!
  194.  
  195.         MOVEA.L    TheWindow(A6),A0    ; get the window pointer
  196.         MOVE.W    WindowKind(A0),D0    ; what kind of window was it?
  197.         BPL.S    Exit            ; DA windows are negitive
  198.  
  199.         MOVE.W    #True,Result(A6)    ; return true to the caller
  200. Exit        UNLK    A6            ; destroy the link
  201.         MOVEA.L    (SP)+,A0        ; pull off the return address
  202.         ADDA.L    #ParamSize,SP        ; strip all of the caller's parameters
  203.         JMP    (A0)            ; return to the caller
  204.  
  205.         DbgInfo    IsDAWind        ; this name will appear in the debugger
  206.         ENDF
  207.  
  208. * ================================================
  209. * FUNCTION IsAppWindow(window: WindowPtr): BOOLEAN;
  210. * ================================================
  211. * Check to see if a window belongs to the application. If the window pointer
  212. * passed was NIL, then it could not be an application window. WindowKinds
  213. * that are negative belong to the system and windowKinds less than userKind
  214. * are reserved by Apple except for windowKinds equal to dialogKind, which
  215. * means it is a dialog.
  216. * In order to reduce the chance of accidentally treating some window
  217. * as an AppWindow that shouldn't be, we'll only return true if the windowkind
  218. * is userKind. If you add different kinds of windows to Sample you'll need
  219. * to change how this all works.
  220.  
  221.         SEG    'Main'
  222. IsAppWindow    FUNC    EXPORT            ; any source file can use this routine
  223.  
  224. StackFrame    RECORD    {A6Link},DECR        ; build a stack frame record
  225. Result        DS.W    1            ; function's result returned to caller
  226. ParamBegin    EQU    *            ; start parameters after this point
  227. TheWindow    DS.L    1            ; a window's pointer passed by caller
  228. ParamSize    EQU    ParamBegin-*        ; size of all the passed parameters
  229. RetAddr     DS.L    1            ; place holder for return address
  230. A6Link        DS.L    1            ; place holder for A6 link
  231. LocalSize    EQU     *            ; size of all the local variables
  232.         ENDR
  233.  
  234.         WITH    StackFrame        ; cover our local stack frame
  235.         LINK    A6,#LocalSize        ; allocate our local stack frame
  236.  
  237.         MOVE.W    #False,Result(A6)    ; first, initialize the result
  238.         CMPI.L    #NIL,TheWindow(A6)    ; valid pointer?
  239.         BEQ.S    Exit            ; it was NIL, look out!
  240.  
  241.         MOVEA.L    TheWindow(A6),A0    ; get the window pointer
  242.         MOVE.W    WindowKind(A0),D0    ; what kind of window was it?
  243.         CMPI.W    #UserKind,D0        ; was it an application window?
  244.         BNE.S    Exit            ; no, result is going to be false
  245.  
  246.         MOVE.W    #True,Result(A6)    ; return true to the caller
  247.  
  248. Exit        UNLK    A6            ; destroy the link
  249.         MOVEA.L    (SP)+,A0        ; pull off the return address
  250.         ADDA.L    #ParamSize,SP        ; strip all of the caller's parameters
  251.         JMP    (A0)            ; return to the caller
  252.  
  253.         DbgInfo    IsAppWin        ; this name will appear in the debugger
  254.         ENDF
  255.  
  256. * ================================================
  257. * PROCEDURE AlertUser;
  258. * ================================================
  259. * Display an alert that tells the user an error occurred, then exit the program.
  260. * This routine is used as an ultimate bail-out for serious errors that prohibit
  261. * the continuation of the application. Errors that do not require the termination
  262. * of the application should be handled in a different manner. Error checking and
  263. * reporting has a place even in the simplest application. For simplicity, the alert
  264. * displayed here only says that an error occurred, but not what it was. There are
  265. * various methods available for being more specific.
  266.  
  267.         SEG    'Main'        ; case sensitive
  268. AlertUser    PROC    EXPORT            ; any source file can use this routine
  269.  
  270. StackFrame    RECORD    {A6Link},DECR        ; build a stack frame record
  271. ParamBegin    EQU    *            ; start parameters after this point
  272. ParamSize    EQU    ParamBegin-*        ; size of all the passed parameters
  273. RetAddr     DS.L    1            ; place holder for return address
  274. A6Link        DS.L    1            ; place holder for A6 link
  275. LocalSize    EQU     *            ; size of all the local variables
  276.         ENDR
  277.  
  278.         WITH    StackFrame        ; cover our local stack frame
  279.         LINK    A6,#LocalSize        ; allocate our local stack frame
  280.  
  281.         CLR.W    -(SP)            ; space for result of Alert
  282.         MOVE.W    #rUserAlert,-(SP)    ; resource for alert dialog
  283.         CLR.L    -(SP)            ; no filter procedure used here
  284.         _Alert                ; read the resource and display it
  285.         MOVE.W    (SP)+,D0        ; I don't care which item is was
  286.         _ExitToShell            ; we're out of here, no error recovery
  287.  
  288. Exit        UNLK    A6            ; destroy the link
  289.         MOVEA.L    (SP)+,A0        ; pull off the return address
  290.         ADDA.L    #ParamSize,SP        ; strip all of the caller's parameters
  291.         JMP    (A0)            ; return to the caller
  292.  
  293.         DbgInfo    AlrtUser        ; this name will appear in the debugger
  294.         ENDP
  295.  
  296. * ================================================
  297. * FUNCTION DoCloseWindow(window: WindowPtr) : BOOLEAN;
  298. * ================================================
  299. * At this point, if there was a document associated with a window, you could
  300. * do any document saving processing if it is 'dirty'.  DoCloseWindow would
  301. * return TRUE if the window actually closes, i.e., the user does not cancel
  302. * from a save dialog. This result is handy when the user quits an application,
  303. * but then cancels a save of a document associated with a window. We also added
  304. * code to close the application window since otherwise, the termination routines
  305. * would never stop looping, waiting for FrontWindow to return NIL.
  306.  
  307.          SEG    'Main'            ; case sensitive
  308. DoCloseWindow    FUNC    EXPORT            ; any source file can use this routine
  309.  
  310. StackFrame    RECORD    {A6Link},DECR        ; build a stack frame record
  311. Result        DS.W    1            ; function's result returned to caller
  312. ParamBegin    EQU    *            ; start parameters after this point
  313. WindowPtr    DS.L    1            ; passed window pointer parameter
  314. ParamSize    EQU    ParamBegin-*        ; size of all the passed parameters
  315. RetAddr     DS.L    1            ; place holder for return address
  316. A6Link        DS.L    1            ; place holder for A6 link
  317. LocalSize    EQU     *            ; size of all the local variables
  318.         ENDR
  319.  
  320.         WITH    StackFrame        ; cover our local stack frame
  321.         LINK    A6,#LocalSize        ; allocate our local stack frame
  322.  
  323.         MOVE.W    #True,Result(A6);    ; initialize the function's result
  324.  
  325.         CLR.W    -(SP)            ; space for result of IsDAWindow
  326.         MOVE.L    WindowPtr(A6),-(SP)    ; pass the window pointer
  327.         BSR    IsDAWindow
  328.         MOVE.W    (SP)+,D0        ; result of IsDAWindow
  329.         CMPI.W    #True,D0
  330.         BNE.S    @1            ; this wasn't a DA window
  331.  
  332.         MOVEA.L    WindowPtr(A6),A0    ; get window pointer
  333.         MOVE.W    WindowKind(A0),-(SP)    ; pass the refNum of DA
  334.         _CloseDeskAcc
  335.         BRA.S    Exit            ; all done
  336.  
  337. @1        CLR.W    -(SP)            ; space for result of IsAppWindow
  338.         MOVE.L    WindowPtr(A6),-(SP)    ; pass a the window pointer
  339.         BSR    IsAppWindow
  340.         MOVE.W    (SP)+,D0        ; result of IsAppWindow
  341.         CMPI.W    #True,D0
  342.         BNE.S    Exit            ; it wasn't our application's window
  343.  
  344.         MOVE.L    WindowPtr(A6),-(SP)    ; close window, it shouldn't be a dialog
  345.         _CloseWindow            ; close the application window
  346.  
  347. Exit        UNLK    A6            ; destroy the link
  348.         MOVEA.L    (SP)+,A0        ; pull off the return address
  349.         ADDA.L    #ParamSize,SP        ; strip all of the caller's parameters
  350.         JMP    (A0)            ; return to the caller
  351.  
  352.         DbgInfo    ClosWind        ; this name will appear in the debugger
  353.         ENDF
  354.  
  355. * ================================================
  356. * PROCEDURE Terminate;
  357. * ================================================
  358. * Clean up the application and exit. We close all of the windows so that
  359. * they can update their documents, if any.  We don't have much to do here.
  360. * Just close our windows and then exit.  If we find out that a Cancel has
  361. * occurred (DoCloseWindow will return False) we won't exit to the shell,
  362. * but will simply exit this procedure.
  363.  
  364.         SEG    'Main'            ; case sensitive
  365. Terminate    PROC    EXPORT
  366.  
  367. StackFrame    RECORD    {A6Link},DECR        ; build a stack frame record
  368. ParamBegin    EQU    *            ; start parameters after this point
  369. ParamSize    EQU    ParamBegin-*        ; size of all the passed parameters
  370. RetAddr     DS.L    1            ; place holder for return address
  371. A6Link        DS.L    1            ; place holder for A6 link
  372. WindowPtr    DS.L    1            ; local variable for a window pointer
  373. Closed        DS.W    1            ; local variable for looping
  374. LocalSize    EQU     *            ; size of all the local variables
  375.         ENDR
  376.  
  377.         IMPORT    DoCloseWindow
  378.  
  379.         WITH    StackFrame        ; cover our local stack frame
  380.         LINK    A6,#LocalSize        ; allocate our local stack frame
  381.  
  382.         MOVE.W    #True,Closed(A6)    ; initialize local variable
  383.  
  384. Loop        CLR.L    -(SP)            ; space for front window pointer
  385.         _FrontWindow
  386.         MOVE.L    (SP)+,WindowPtr(A6)    ; get the front window pointer
  387.         CMPI.L    #NIL,WindowPtr(A6)    ; is there a front window?
  388.         BEQ.S    @1            ; there are no more windows
  389.  
  390.         CLR.W    -(SP)            ; space for result of DoCloseWindow
  391.         MOVE.L    WindowPtr(A6),-(SP)    ; pass the window pointer
  392.         BSR    DoCloseWindow        ; close all our windows
  393.         MOVE.W    (SP)+,Closed(A6)    ; get result of DoCloseWindow
  394.         CMPI.W    #True,Closed(A6)    ; what's the result of DoCloseWindow?
  395.         BNE.S    Exit            ; user didn't want to close that window
  396.  
  397.         BRA.S    Loop            ; loop again and close the next window
  398.  
  399. @1        CMPI.W    #True,Closed(A6)    ; should we really terminate?
  400.         BNE.S    Exit            ; no, exit this procedure
  401.  
  402.         _ExitToShell            ; we're done, let's get out of here
  403.  
  404. Exit        UNLK    A6            ; destroy the link
  405.         MOVEA.L    (SP)+,A0        ; pull off the return address
  406.         ADDA.L    #ParamSize,SP        ; strip all of the caller's parameters
  407.         JMP    (A0)            ; return to the caller
  408.  
  409.         DbgInfo    Terminat        ; this name will appear in the debugger
  410.         ENDP
  411.  
  412. * ================================================
  413. * PROCEDURE AdjustMenus;
  414. * ================================================
  415. * Enable and disable menus based on the current state.  The user can only select
  416. * enabled menu items. We set up all the menu items before calling MenuSelect or
  417. * MenuKey, since these are the only times that a menu item can be selected. Note
  418. * that MenuSelect is also the only time the user will see menu items. This
  419. * approach to deciding what enable/disable state a menu item has the advantage
  420. * of concentrating all the decision making in one routine, as opposed to being
  421. * spread throughout the application.  Other application designs may take a
  422. * different approach that are just as valid.
  423.  
  424.         SEG    'Main'            ; case sensitive
  425. AdjustMenus    PROC    EXPORT            ; any source file can use this routine
  426.  
  427. StackFrame    RECORD    {A6Link},DECR        ; build a stack frame record
  428. ParamBegin    EQU    *            ; start parameters after this point
  429. ParamSize    EQU    ParamBegin-*        ; size of all the passed parameters
  430. RetAddr     DS.L    1            ; place holder for return address
  431. A6Link        DS.L    1            ; place holder for A6 link
  432. FrontMost    DS.L    1            ; local copy of the front window
  433. Menu        DS.L    1            ; local copy of the menu handle
  434. LocalSize    EQU     *            ; size of all the local variables
  435.         ENDR
  436.  
  437.         WITH    StackFrame        ; cover our local stack frame
  438.         LINK    A6,#LocalSize        ; allocate our local stack frame
  439.  
  440.         CLR.L    -(SP)            ; space for result
  441.         _FrontWindow
  442.         MOVE.L    (SP)+,FrontMost(A6)    ; save the front window
  443.  
  444. Exit        UNLK    A6            ; destroy the link
  445.         MOVEA.L    (SP)+,A0        ; pull off the return address
  446.         ADDA.L    #ParamSize,SP        ; strip all of the caller's parameters
  447.         JMP    (A0)            ; return to the caller
  448.  
  449.         DbgInfo    AdjstMnu        ; this name will appear in the debugger
  450.         ENDP
  451.  
  452. * ================================================
  453. * PROCEDURE GetGlobalMouse(VAR mouse: Point);
  454. * ================================================
  455. * Get the global coordinates of the mouse. When you call OSEventAvail
  456. * it will return either a pending event or a null event. In either case,
  457. * the where field of the event record will contain the current position
  458. * of the mouse in global coordinates and the modifiers field will reflect
  459. * the current state of the modifiers. Another way to get the global
  460. * coordinates is to call GetMouse and LocalToGlobal, but that requires
  461. * being sure that thePort is set to a valid port.}
  462.  
  463.         SEG    'Main'            ; case sensitive
  464. GetGlobalMouse    PROC    EXPORT            ; any source file can use this routine
  465.  
  466. StackFrame    RECORD    {A6Link},DECR        ; build a stack frame record
  467. ParamBegin    EQU    *            ; start parameters after this point
  468. Mouse        DS.L    1            ; passed reference to mouse position
  469. ParamSize    EQU    ParamBegin-*        ; size of all the passed parameters
  470. RetAddr     DS.L    1            ; place holder for return address
  471. A6Link        DS.L    1            ; place holder for A6 link
  472. TheEvent     DS    EventRecord         ; local copy of the event record
  473. LocalSize    EQU     *            ; size of all the local variables
  474.         ENDR
  475.  
  476.         WITH    StackFrame        ; cover our local stack frame
  477.         LINK    A6,#LocalSize        ; allocate our local stack frame
  478.  
  479.         MOVE.W    #NoEvents,D0        ; we aren't interested in any events
  480.         LEA    TheEvent(A6),A0        ; point to event record
  481.         _OSEventAvail            ; just the mouse position
  482.         MOVE.L    Mouse(A6),A0        ; deref address of mouse
  483.         MOVE.L    TheEvent.Where(A6),(A0)    ; stuff new value
  484.  
  485.         UNLK    A6            ; destroy the link
  486.         MOVEA.L    (SP)+,A0        ; pull off the return address
  487.         ADDA.L    #ParamSize,SP        ; strip all of the caller's parameters
  488.         JMP    (A0)            ; return to the caller
  489.  
  490.         DbgInfo    GetGlobalMouse        ; this name will appear in the debugger
  491.         ENDP
  492.  
  493. * ================================================
  494. * PROCEDURE DrawClut(window: WindowPtr);
  495. * ================================================
  496. *
  497. * This procedure finds the max depth device for the window port and uses that
  498. * device to draw the colors in the window.
  499.  
  500.         SEG    'Main'            ; case sensitive
  501. DrawClut    PROC    EXPORT            ; any source file can use this routine
  502.  
  503. StackFrame    RECORD    {A6Link},DECR        ; build a stack frame record
  504. ParamBegin    EQU    *            ; start parameters after this point
  505. WindowPtr    DS.L    1            ; passed parameter of the window pointer
  506. ParamSize    EQU    ParamBegin-*        ; size of all the passed parameters
  507. RetAddr     DS.L    1            ; place holder for return address
  508. A6Link        DS.L    1            ; place holder for A6 link
  509. Color        DS.W    3
  510. OldGDev        DS.l    1            ; save current GDevice
  511. wRectBR        DS.L    1            ; 
  512. wRectTL        DS.L    1            ; local storage for rect
  513. LocalSize    EQU     *            ; size of all the local variables
  514.         ENDR
  515.  
  516.         WITH    StackFrame,ClutWData    ; cover our local stack frame
  517.         LINK    A6,#LocalSize        ; allocate our local stack frame
  518.  
  519.         MOVE.L    WindowPtr(A6),-(SP)
  520.         _SetPort            ; set the current port to use
  521.         
  522.         MOVE.L    theGDevice,OldGDev(a6)    ; save current device
  523.         
  524. ; Now we want to check the max device the window is on in order to use its color table
  525. ; to display colors. 
  526.  
  527.         move.l    WindowPtr(a6), A0    ; get pointer to port
  528.         ADD.L    #$10,A0            ; point to rectangle
  529.         LEA    wRectTL(a6),a1
  530.         MOVE.L    (a0)+,(a1)+        ; copy topleft
  531.         MOVE.L    (a0)+,(a1)+        ; copy bottomright
  532.         PEA    wRectTL(a6)        ; push rect
  533.         _LocalToGlobal            ; globalize topleft
  534.         PEA    wRectBR(a6)        ; push rect
  535.         _LocalToGlobal            ; globalize bottomright
  536.  
  537.         clr.l     -(sp)            ; make room for result 
  538.         PEA    wRectTL(a6)        ; push rect
  539.         _GetMaxDevice            ; don't touch result
  540.         
  541.         CMP.L    #0,(sp)            ; check result
  542.         BEQ    @1            ; if nil use current device
  543.         
  544.         _SetGDevice            ; the max dev is in the stack
  545.         
  546. @1        Move.L    #255,D3
  547.         Move.w    #4,-(SP)
  548.         Move.w    #4,-(SP)
  549.         _PenSize
  550. ClutLoop:
  551.         Move.L    D3,-(SP)
  552.         Pea    Color(A6)
  553.         _Index2Color
  554.         Pea    Color(A6)
  555.         _RGBForeColor
  556.                         ; Build 16*16 array = 256 colors
  557.         Move.w    D3,D0            ; Current color index
  558.         And.w    #$000F,D0        ; mod 16 (16 colors per row)
  559.         ASL.w    #2,D0            ; times 4 (pen width)
  560.         Move.w    D0,-(SP)        ; set ‘left’ for MoveTo
  561.         Move.w    D3,D0            ; Current index
  562.         LSR.w    #4,D0            ; divided by 16 (and lose low order bits)
  563.         ASL.w    #2,D0            ; times 4 (pen width)
  564.         Move.w    D0,-(SP)        ; set ‘top’ for MoveTo
  565.         _MoveTo
  566.         Clr.l    -(SP)
  567.         _Line                ; Line length of zero ‘stamps’ in pen
  568.         DBRA    D3,ClutLoop
  569.  
  570. Exit        MOVE.L    OldGDev(a6),theGDevice    ; restore current device
  571.  
  572.         UNLK    A6            ; destroy the link
  573.         MOVEA.L    (SP)+,A0        ; pull off the return address
  574.         ADDA.L    #ParamSize,SP        ; strip all of the caller's parameters
  575.         JMP    (A0)            ; return to the caller
  576.  
  577.         DbgInfo    DrawClut
  578.         ENDP
  579.         
  580. * ================================================
  581. * PROCEDURE NulMouse(window: WindowPtr; event: EventRecord);
  582. * ================================================
  583.         SEG    'Main'            ; case sensitive
  584. NulMouse    PROC    EXPORT
  585.  
  586. StackFrame    RECORD    {A6Link},DECR        ; build a stack frame record
  587. ParamBegin    EQU    *            ; start parameters after this point
  588. WindowPtr    DS.L    1            ; passed parameter of the window pointer
  589. EventPtr    DS.L    1            ; pointer to the event record
  590. ParamSize    EQU    ParamBegin-*        ; size of all the passed parameters
  591. RetAddr     DS.L    1            ; place holder for return address
  592. A6Link        DS.L    1            ; place holder for A6 link
  593. * insert locals here
  594. LocalSize    EQU     *            ; size of all the local variables
  595.         ENDR
  596. ;        IMPORT    
  597.  
  598.         WITH    StackFrame        ; cover our local stack frame
  599.         LINK    A6,#LocalSize        ; allocate our local stack frame
  600.         
  601.  
  602. Exit        UNLK    A6            ; destroy the link
  603.         MOVEA.L    (SP)+,A0        ; pull off the return address
  604.         ADDA.L    #ParamSize,SP        ; strip all of the caller's parameters
  605.         JMP    (A0)            ; return to the caller
  606.  
  607.         DbgInfo    NulMouse
  608.         ENDP
  609.  
  610. * ================================================
  611. * PROCEDURE AdjustCursor(mouse: Point; region: RgnHandle);
  612. * ================================================
  613. * Change the cursor's shape, depending on its position. This also calculates the
  614. * region where the current cursor resides (for WaitNextEvent). If the mouse is
  615. * ever outside of that region, an event would be generated, causing this routine
  616. * to be called, allowing us to change the region to the region the mouse is
  617. * currently in. If there is more to the event than just the mouse moved, we
  618. * get called before the event is processed to make sure the cursor is the right
  619. * one. In any (ahem) event, this is called again before we fall back into WNE.
  620. * 1.02 - Removed the mouse position parameter and instead use the current position
  621. * of the mouse by calling GetMouse and LocalToGlobal.
  622.  
  623.         SEG    'Main'            ; case sensitive
  624. AdjustCursor    PROC    EXPORT
  625.  
  626. StackFrame    RECORD    {A6Link},DECR        ; build a stack frame record
  627. ParamBegin    EQU    *            ; start parameters after this point
  628. Where        DS.L    1            ; the mouse location passed to us
  629. MouseRegion    DS.L    1            ; passed pointer to current region
  630. ParamSize    EQU    ParamBegin-*        ; size of all the passed parameters
  631. RetAddr     DS.L    1            ; place holder for return address
  632. A6Link        DS.L    1            ; place holder for A6 link
  633. FrontMost    DS.L    1            ; local pointer to the front window
  634. ArrowRgn    DS.L    1            ; local handle to the arrow cursor region
  635. PlusRgn        DS.L    1            ; local handle to the plus cursor region
  636. LocalSize    EQU     *            ; size of all the local variables
  637.         ENDR
  638.  
  639.         IMPORT    IsDAWindow,IsAppWindow
  640.  
  641.         WITH    StackFrame        ; cover our local stack frame
  642.         LINK    A6,#LocalSize        ; allocate our local stack frame
  643.  
  644.         CLR.W    -(SP)            ; space for result of IsAppWindow
  645.         CLR.L    -(SP)            ; space for result of FrontWindow
  646.         _FrontWindow            ; push front window pointer
  647.         MOVE.L    (SP),FrontMost(A6)    ; copy pointer and keep it on stack
  648.         BSR    IsDAWindow        ; is this an application window?
  649.         MOVE.W    (SP)+,D0
  650.         CMPI.W    #True,D0
  651.         BEQ.W    Exit            ; not our window, don't adjust the cursor
  652.         CMPI.W    #True,G.InBackground
  653.         BEQ.W    Exit            ; and do nothing if we're in the background
  654.  
  655. * ------------- INITIALIZE SOME REGION DATA -------------
  656.  
  657.         CLR.L    -(SP)
  658.         _NewRgn                ; create an empty plus region
  659.         MOVE.L    (SP)+,PlusRgn(A6)
  660.         CLR.L    -(SP)
  661.         _NewRgn                ; create an empty arrow region
  662.         MOVE.L    (SP)+,ArrowRgn(A6)
  663.         MOVE.L    ArrowRgn(A6),-(SP)    ; arrow region handle
  664.         MOVE.W    #ExtremeNeg,-(SP)    ; big left corner
  665.         MOVE.W    #ExtremeNeg,-(SP)    ; big top corner
  666.         MOVE.W    #ExtremePos,-(SP)    ; big right corner
  667.         MOVE.W    #ExtremePos,-(SP)    ; big bottom corner
  668.         _SetRecRgn            ; really big rectangular region
  669.  
  670.         CLR.W    -(SP)
  671.         MOVE.L    FrontMost(A6),-(SP)
  672.         BSR    IsAppWindow        ; is this an application window?
  673.         MOVE.W    (SP)+,D0
  674.         CMPI.W    #True,D0
  675.         BNE.S    @1            ; our window isn't in front?
  676.  
  677. * ------------- CALCULATE THE PLUS REGION -------------
  678.  
  679.         MOVE.L    FrontMost(A6),-(SP)
  680.         _SetPort            ; set the current port to us
  681.         MOVEA.L    FrontMost(A6),A0
  682.         MOVE.W    portBits+bounds+left(A0),D0
  683.         NEG.W    D0            ; offset window's left edge...
  684.         MOVE.W    D0,-(SP)        ; to the screen's left edge
  685.         MOVEA.L    FrontMost(A6),A0
  686.         MOVE.W    portBits+bounds+top(A0),D0
  687.         NEG.W    D0            ; offset window's top edge...
  688.         MOVE.W    D0,-(SP)        ; to the screen's top edge
  689.         _SetOrigin            ; make window rect global
  690.         MOVE.L    PlusRgn(A6),-(SP)    ; handle to empty plus region
  691.         MOVEA.L    FrontMost(A6),A0    ; pointer to our window
  692.         PEA    portRect(A0)        ; window rect's global coordinates
  693.         _RectRgn            ; make global window rect into region
  694.         MOVE.L    PlusRgn(A6),-(SP)    ; get intersection of plus and window region
  695.         MOVEA.L    FrontMost(A6),A0
  696.         MOVE.L    visRgn(A0),-(SP)    ; get front window's visRgn
  697.         MOVE.L    PlusRgn(A6),-(SP)    ; resulting region will be in PlusRgn
  698.         _SectRgn            ; intersection the two regions
  699.         CLR.L    -(SP)            ; reset the origin of our window to 0,0
  700.         _SetOrigin
  701.  
  702. @1        MOVE.L    ArrowRgn(A6),-(SP)    ; the really big rectangular region
  703.         MOVE.L    PlusRgn(A6),-(SP)    ; the region of our window
  704.         MOVE.L    ArrowRgn(A6),-(SP)    ; intersetion of the Arrow and Plus region
  705.         _DiffRgn            ; this is the region where the Arrow shows
  706.         CLR.W    -(SP)            ; space for result of PtInRect
  707.         MOVE.L    Where(A6),-(SP)        ; here's the mouse
  708.         MOVE.L    PlusRgn(A6),-(SP)    ; where the arrow should show up
  709.         _PtInRgn            ; was cursor in the arrow region?
  710.         MOVE.W    (SP)+,D0
  711.         CMPI.W    #True,D0
  712.         BNE.S    @2            ; cursor was in arrow region
  713.  
  714. * ------------- SET THE CURSOR AND NEW MOUSE REGION -------------
  715.  
  716.         CLR.L    -(SP)            ; space for result
  717.         MOVE.W    #plusCursor,-(SP)    ; I want the plus cursor now!
  718.         _GetCursor
  719.         MOVEA.L    (SP)+,A0        ; get the handle
  720.         CMPA.L    #NIL,A0
  721.         BEQ.S    Exit            ; check for NIL like a good boy
  722.         MOVE.L    (A0),-(SP)        ; got the plus cursor
  723.         _SetCursor            ; set cursor to plus
  724.         MOVE.L    PlusRgn(A6),-(SP)    ; current region containing cursor
  725.         MOVE.L    MouseRegion(A6),-(SP)    ; set it to the new region
  726.         _CopyRgn
  727.         BRA.S    @3            ; we're done, get out of here
  728.  
  729. @2        PEA    QD.Arrow        ; got arrow cursor at InitGraf
  730.         _SetCursor            ; set cursor to the Arrow
  731.         MOVE.L    ArrowRgn(A6),-(SP)    ; current region containing cursor
  732.         MOVE.L    MouseRegion(A6),-(SP)    ; set it to the new region
  733.         _CopyRgn
  734.  
  735. @3        MOVE.L    PlusRgn(A6),-(SP)    ; dispose of our two temporary regions
  736.         _DisposRgn
  737.         MOVE.L    ArrowRgn(A6),-(SP)
  738.         _DisposRgn
  739.  
  740. Exit        UNLK    A6            ; destroy the link
  741.         MOVEA.L    (SP)+,A0        ; pull off the return address
  742.         ADDA.L    #ParamSize,SP        ; strip all of the caller's parameters
  743.         JMP    (A0)            ; return to the caller
  744.  
  745.         DbgInfo    AdjstCur        ; this name will appear in the debugger
  746.         ENDP
  747.  
  748.         END                ; end of this source file
  749.